const { app, BrowserWindow, Menu } = require('electron');
const menuTemplate = require('./menuTemplate');
const isDev = require('electron-is-dev');
const path = require('path');

let mainWindow;

app.on('ready', () => {
  mainWindow = new BrowserWindow({
    //创建窗口 只可以在main使用
    width: 1024,
    height: 680,
    //设置网页的功能
    webPreferences: {
      nodeIntegration: true, //配置使用node
      enableRemoteModule: true,
    },
  });
  const urlLocation = isDev
    ? 'http://localhost:3000'
    : `file://${path.join(__dirname, '../build/index.html')}`;
  // set the menu
  let menu = Menu.buildFromTemplate(menuTemplate);
  Menu.setApplicationMenu(menu);
  // 创建窗口
  mainWindow.loadURL(urlLocation);
  // 打开控制台
  isDev && mainWindow.webContents.openDevTools();

  // 其余事件监听
  require('./ipcMain/index');
});
